﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SavoryBL;
using System.Data;

namespace WebApplication.ManageAccount
{
    public partial class Edit_Account1 : System.Web.UI.Page
    {
        SavoryUserDetails userDtlObj = new SavoryUserDetails();
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    if (Session["UserID"] != null && Session["UserID"].ToString() != "Guest")
                    {
                        CountryService service = new CountryService();
                        List<string> country = service.GetCountry();
                        ddlCountry.DataSource = country;
                        ddlCountry.DataBind();
                        ddlCountry.Items.Insert(0, "Country");
                        getUserDetails();

                        ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("divbreadcrum")).InnerHtml = @"<a href='../Menu.aspx'>Home</a> > <a href='Account_Overview.aspx'>My Account Overview</a> > <span>Edit Account</span>";
                    }
                    else
                    {
                        ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("divbreadcrum")).InnerHtml = @"<a href='../default.aspx'>Home</a> > <a href='Account_Overview.aspx'>My Account Overview</a> > <span>Edit Account</span>";
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public void getUserDetails()
        {
            try
            {
                DataSet ds = userDtlObj.GetUserProfileDetailsByUserID(Convert.ToInt32(Session["ID"].ToString()));
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    txt_FisrtName.Text = ds.Tables[0].Rows[0]["FirstName"].ToString();
                    txt_LastName.Text = ds.Tables[0].Rows[0]["LastName"].ToString();
                    txt_EmailID.Text = ds.Tables[0].Rows[0]["EmailID"].ToString();
                    txt_ContactInfo1.Text = ds.Tables[0].Rows[0]["ContactNo1"].ToString();
                    txt_ContactInfo2.Text = ds.Tables[0].Rows[0]["ContactNo2"].ToString();
                    ddlCountry.SelectedValue = userDtlObj.GetCountryNameByCountryID(Convert.ToInt32(ds.Tables[0].Rows[0]["CountryID"].ToString()));
                }

            }
            catch (Exception ex)
            {
            }
        }
        protected void btn_Update_Click(object sender, EventArgs e)
        {
            try
            {

                if (Session["UserID"] != null && Session["UserID"].ToString() != "")
                {
                    string FirstName = txt_FisrtName.Text.Trim();
                    string LastName = txt_LastName.Text.Trim();
                    string Country = Request.Form.GetValues("ctl00$MainContent$ddlCountry")[0];
                    string City = Request.Form.GetValues("ctl00$MainContent$ddlCity")[0];
                    string countryCode = txt_CountryCode.Text.Trim();
                    string Contact1 = txt_ContactInfo1.Text.Trim();
                    string Contact2 = txt_ContactInfo2.Text.Trim();
                    string EmailID = txt_EmailID.Text.Trim();
                    ResponseStatus status = ResponseStatus.Failure;
                    status = userDtlObj.UserUpdateAccountDetails(FirstName, LastName, Contact1, EmailID, countryCode, City, Convert.ToInt32(Session["ID"].ToString()));
                    if (status == ResponseStatus.Success)
                    {
                        div_UpdatePwdMsg.Style["display"] = "block";
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
    }
}